package pl.ydp.components.mathcell.mathrecognizer.engine
{
	import flash.geom.Rectangle;
	
	import pl.ydp.components.mathcell.mathrecognizer.geometry.AngleTrend;
	
	public class Parameters
	{
		
		public static function ParametersSetUp(_width:Number, _height:Number):void{
			
			CHAR_WIDTH = _width;
			CHAR_HEIGHT = _height;
			
			CHAR_NORMALIZED_WIDTH = _width*CHAR_SIZE_COEFF;
			CHAR_NORMALIZED_HEIGHT = _height*CHAR_SIZE_COEFF;
			
			FIELD_NORMALIZED = new Rectangle(0,0,CHAR_NORMALIZED_WIDTH, CHAR_NORMALIZED_HEIGHT);
			
			// INTERPOLATION
			
			INTERP_VECTOR_LENGTH = CHAR_SIZE_COEFF*0.5*Math.pow(2, 0.5);//*128/((128*3+CHAR_WIDTH)/4);
			
			
			// DOT PARAMETERS
			
			DOT_MAX_SIZE = CHAR_NORMALIZED_HEIGHT / 7;//10;
			DOT_FIELD_COEFF_MAX = 2.5;
			
			// LINE PARAMTERES
			
			MIN_LINE_LENGTH = Math.floor(6/INTERP_VECTOR_LENGTH);
			
			// CURVE PARAMETERS
			
			CURVE_LENGTH_MIN = 14/INTERP_VECTOR_LENGTH;
			CURVE_ANGLE_MIN = AngleTrend.THRESHOLD_CURVE*1.5;
			CURVE_ANGLE_STEP_MIN = -0.5; 
			CURVE_ANGLE_STEP_DIFF_MAX = AngleTrend.THRESHOLD_CURVE/2;
			CURVE_BEND_ANGLE_LENGHT = 20;
			CURVE_BEND_ANGLE_DIFF_MAX = AngleTrend.ANGLE_HALF*3/4;
			
			// LOOP PARAMETERS
			
			LOOP_MIN_LENGTH = 24/INTERP_VECTOR_LENGTH;
			LOOP_MIN_DIAMETER = CHAR_NORMALIZED_HEIGHT/6;
			LOOP_DIAMETER_SECOND_MIN = LOOP_MIN_DIAMETER/2;
			LOOP_DIAMETERS_RATIO_MIN = 0.2;
			LOOP_MIN_ANGLE_DIFF = AngleTrend.ANGLE_HALF;
			LOOP_MAX_CLOSURE_DISTANCE = MAX_CONNECTION_DISTANCE*1.5;
			LOOP_MAX_CLOSURE_DISTANCE_DIAMETER_COEFF = 1/3;
			LOOP_MAX_CLOSURE_DISTANCE_DIAMETER2_COEFF = 0.8;
			LOOP_CLOSURE_DISTANCE_DIAMETER_COEFF_MAX_SUFFICIENT = 1/4;
			
			// HELIX PARAMTERES
			
			HELIX_ANGLE_CATCH_DIFF_MIN = AngleTrend.THRESHOLD_CURVE/2;
			
			// WAVE PARAMTERES
			
			WAVE_VERTICAL_TOLERANCE_COEFF = -0.35;
			WAVE_FIELD_COEFF_MIN = 1;
			WAVE_FIELD_COEFF_MAX = 8;
			WAVE_ANGLE_MAX = AngleTrend.ANGLE_22_5;
			
			//  EXTRACTOR PARAMETERS
			
			EXTRACTOR_LOOP_SEEK_STEP = Math.round(MIN_LINE_LENGTH);
			
			// JOINT PARAMETERS
			
			MAX_JOINT_DISTANCE = CHAR_NORMALIZED_HEIGHT / 12;
			JOINT_DISTANCE_MAX_VECTORS_COUNT = Math.floor(MAX_JOINT_DISTANCE/INTERP_VECTOR_LENGTH);
			MAX_JOINT_LINE_ANGLE_DIFF = AngleTrend.THRESHOLD_CURVE*2/3;
			MAX_JOINT_LINE_ANGLE_JOINT_DIFF = AngleTrend.THRESHOLD_CURVE/2;
			MAX_JOINT_CURVE_ANGLE_JOINT_DIFF = AngleTrend.ANGLE_RIGHT;
			MAX_JOINT_CURVE_ANGLE_JOINT_DIFF_NEGATIVE = -1*AngleTrend.ANGLE_RIGHT/3; 
			
			// ABSORBTION PARAMETERS
			
			ABSORBTION_DOT_MAX_DISTANCE = CHAR_NORMALIZED_HEIGHT / 12;
			ABSORBTION_LOOP_COG_MAX_DISTANCE = CHAR_NORMALIZED_HEIGHT / 12;
			ABSORBTION_LOOP_SIZE_RATIO = 1.25;
			ABSORBTION_LINE_ANGLE_DIFF = AngleTrend.THRESHOLD_STILL;
			ABSORBTION_LINE_DISTANCE_MAX = CHAR_NORMALIZED_HEIGHT / 24;
			
			// CONNECTION
			
			MAX_CONNECTION_DISTANCE = CHAR_NORMALIZED_HEIGHT / 9;
			CONNECTION_DISTANCE_MAX_VECTORS_COUNT = Math.floor(MAX_CONNECTION_DISTANCE/INTERP_VECTOR_LENGTH);
			
			// INTERPOLATION
			
			MIN_VECTOR_LENGTH = INTERP_VECTOR_LENGTH/2;
			MAX_VECTOR_LENGTH = INTERP_VECTOR_LENGTH*3;
			
			// DECIMATION
						
			MIN_PURE_VECTOR_LENGTH = INTERP_VECTOR_LENGTH*3;
			
			// JUNKS
			
			JUNKS_LINE_LENGTH_MIN = Math.round(MIN_LINE_LENGTH*1.2);
			JUNKS_CURVE_LENGTH_MIN = Math.round(CURVE_LENGTH_MIN*1.5);
			
			// MODEL MATCHING
			
			CANDIDATE_IS_CHILDREN = 1024;
			CANDIDATE_CHILDREN_OFFSET = 4096;
			
			MAX_ZOOM = 1.5;
		}
		
		
		public static const CHAR_SIZE_COEFF:Number = 1;
		
		public static var CHAR_WIDTH:Number;
		public static var CHAR_HEIGHT:Number;
		
		public static var CHAR_NORMALIZED_WIDTH:Number;
		public static var CHAR_NORMALIZED_HEIGHT:Number;
		
		public static var FIELD_NORMALIZED:Rectangle;
		

		// CONNECTION PARAMETERS
		
		public static var MAX_CONNECTION_DISTANCE:Number;
		public static var CONNECTION_DISTANCE_MAX_VECTORS_COUNT:Number;
		
		// JOINT PARAMS
		
		public static var MAX_JOINT_DISTANCE:Number;
		public static var JOINT_DISTANCE_MAX_VECTORS_COUNT:Number;
		public static var MAX_JOINT_LINE_ANGLE_DIFF:Number;
		public static var MAX_JOINT_LINE_ANGLE_JOINT_DIFF:Number;
		public static var MAX_JOINT_CURVE_ANGLE_JOINT_DIFF:Number;
		public static var MAX_JOINT_CURVE_ANGLE_JOINT_DIFF_NEGATIVE:Number;
		
		// ABSORB PARAMS
		
		public static var ABSORBTION_DOT_MAX_DISTANCE:Number;
		public static var ABSORBTION_LOOP_COG_MAX_DISTANCE:Number;
		public static var ABSORBTION_LOOP_SIZE_RATIO:Number;
		public static var ABSORBTION_LINE_ANGLE_DIFF:Number;
		public static var ABSORBTION_LINE_DISTANCE_MAX:Number;
		
		public static var MIN_PURE_VECTOR_LENGTH:Number;
		
		public static var INTERP_VECTOR_LENGTH:Number;
		public static var MIN_VECTOR_LENGTH:Number;
		public static var MAX_VECTOR_LENGTH:Number;
		
		public static var MIN_LINE_LENGTH:Number;
		
		// JUNKS COLLECTOR
		
		public static var JUNKS_LINE_LENGTH_MIN:Number;
		public static var JUNKS_CURVE_LENGTH_MIN:Number;
		
		
		// MODEL MATCHING
		
		public static var CANDIDATE_IS_CHILDREN:Number;
		public static var CANDIDATE_CHILDREN_OFFSET:Number;
		
		// EXTRACTOR PARAMETERS
		
		public static var EXTRACTOR_LOOP_SEEK_STEP:Number
		
		// CURVE PARAMETERS
		
		public static var CURVE_LENGTH_MIN:Number;
		public static var CURVE_ANGLE_MIN:Number;
		public static var CURVE_ANGLE_STEP_MIN:Number;
		public static var CURVE_ANGLE_STEP_DIFF_MAX:Number;
		public static var CURVE_BEND_ANGLE_LENGHT:Number;
		public static var CURVE_BEND_ANGLE_DIFF_MAX:Number;
		
		// LOOP PARAMETERS
		
		public static var LOOP_MIN_LENGTH:Number;
		public static var LOOP_MIN_DIAMETER:Number;
		public static var LOOP_DIAMETER_SECOND_MIN:Number;
		public static var LOOP_DIAMETERS_RATIO_MIN:Number;
		public static var LOOP_MIN_ANGLE_DIFF:Number;
		public static var LOOP_MAX_CLOSURE_DISTANCE:Number;
		public static var LOOP_MAX_CLOSURE_DISTANCE_DIAMETER_COEFF:Number;
		public static var LOOP_MAX_CLOSURE_DISTANCE_DIAMETER2_COEFF:Number;
		public static var LOOP_CLOSURE_DISTANCE_DIAMETER_COEFF_MAX_SUFFICIENT:Number;
		
		// HELIX PARAMTERES
		
		public static var HELIX_ANGLE_CATCH_DIFF_MIN:Number;
		
		// WAVE PARAMTERES
		
		public static var WAVE_VERTICAL_TOLERANCE_COEFF:Number;
		public static var WAVE_FIELD_COEFF_MIN:Number;  // width/height ratio
		public static var WAVE_FIELD_COEFF_MAX:Number;  // width/height ratio
		public static var WAVE_ANGLE_MAX:Number;  // width/height ratio
		
		// DOT PARAMETERS
		
		public static var DOT_MAX_SIZE:Number;
		public static var DOT_FIELD_COEFF_MAX:Number;
		
		public static var MAX_ZOOM:Number;
		

	}
}